package com.bjpowernode.service.impl;

import com.bjpowernode.constant.Constant;
import com.bjpowernode.entity.TActivity;
import com.bjpowernode.mapper.TActivityMapper;
import com.bjpowernode.query.ActivityQuery;
import com.bjpowernode.query.BaseQuery;
import com.bjpowernode.service.ActivityService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {

    @Resource
    private TActivityMapper tActivityMapper;

    /**
     * 分页查询
     * @param current
     * @return
     */
    @Override
    public PageInfo<TActivity> getActivityByPage(Integer current, ActivityQuery activityQuery) {
        //1.设置查询第几页和每页显示的数量
        PageHelper.startPage(current, Constant.PAGE_SIZE);

        //2.查询用户信息  pageHelper会在sql语句发出之前利用拦截器拼接分页信息
        List<TActivity> tActivityList = tActivityMapper.selectByPage(new BaseQuery(),activityQuery);

        //3.构建pageInfo对象 将上面的查询结果传入
        PageInfo<TActivity> pageInfo = new PageInfo<>(tActivityList);

        return pageInfo;
    }

    @Override
    public TActivity getActivityById(Integer id) {
        TActivity activity = tActivityMapper.selectActivityById(id);

        return activity;
    }
}
